package myoa

import myoa.tool.FileTool

class FileStoreController {
    FileStoreService fileStoreService

    def upload() {

    }

    def uploadDo() {
        FileStore fs = fileStoreService.upload()
        flash.message = "#${fs.id} upload success"
        redirect(action: 'list')
    }

    def list() {
        def numOfFiles = FileTool.baseDir.listFiles().size()
        [files: FileStore.findAll(), numOfFiles: numOfFiles]
    }

    def delete(Long id) {    //todo 事务化
        FileStore fs = FileStore.get(id)
        fs.file.delete()
        fs.delete()
        flash.message = message(code: 'default.delete.success', args: [fs.name])
        redirect(action: 'list')
    }
}
